/** 战斗回路

  By setycyas @2023-10-14
*/

/* 全局设定
*/ 
#Include "..\Class\MyFuns.2.ahk"
#Include "..\Class\FaceDetector.2.ahk"
#Include "..\Class\CommonMacro.2.ahk"
#Include "..\Class\CommonUI.2.ahk"

#Warn
#MaxThreadsPerHotkey 1
SetWorkingDir(A_ScriptDir)

SendMode("Input")
;SendMode("Event")

/* 制作战斗回路的宏类
*/ class BatcirMacro extends CommonMacro {

  /* 新增的宏函数
  */
  ;植物左右连打技能
  _植物左右连打(key){
    local directions := ["left", "right"]
    local isPressingRight := MyFuns.getKeyState("right")
    local isPressingLeft := MyFuns.getKeyState("left")
    local directionIndex := isPressingRight ? 1 : 2
    ;如果左右键都没有按,默认加按一下右键,否则只按拳
    if (!isPressingRight and !isPressingLeft)
      MyFuns.pressKeys(["right", this._keys[1]], [50, 150])
    else
      MyFuns.press(this._keys[1], 150)
    loop 10 {
      MyFuns.press(directions[directionIndex], 150)
      if (!MyFuns.getKeyState(key))
        break
      directionIndex := (directionIndex == 1) ? 2 : 1
    }
  }
  ;植物吞人技能,成功率一般般
  _植物吞人(key){
    local face, back ;, keys, delays
    face := this._face.face()
    back := this._face.back()
    if (face == "right"){
      MyFuns.keyDown("down")
      sleep(30)
      MyFuns.keyDown(face)
      sleep(50)
      MyFuns.keyUp("down")
      sleep(80)
      MyFuns.keyDown("up")
      sleep(80)
      MyFuns.keyUp(face)
      sleep(50)
      MyFuns.keyDown(back)
      sleep(20)
      MyFuns.keyUp("up")
      sleep(80)
      this._down(1)
      sleep(30)
      MyFuns.keyUp(back)
      sleep(30)
      this._up(1)
      /*
      MyFuns.keyUp("up")
      sleep(80)
      MyFuns.keyUp(back)
      sleep(30)
      this._press(1)
      */
    } else {
      MyFuns.keyDown("down")
      sleep(110)
      MyFuns.keyDown(face)
      sleep(30)
      MyFuns.keyUp("down")
      sleep(80)
      MyFuns.keyDown("up")
      sleep(50)
      MyFuns.keyUp(face)
      sleep(30)
      MyFuns.keyDown(back)
      sleep(60)
      MyFuns.keyUp("up")
      sleep(50)
      this._down(1)
      sleep(30)
      MyFuns.keyUp(back)
      sleep(80)
      this._up(1)
    }
  }
  ;下上A之后连打
  _下上A连打(key){
    this._下上A(key)
    sleep(50)
    if (MyFuns.getKeyState(key)) {
      this._连发A(key)
    }
  }
  ;前A之后连打
  _前A连打(key){
    this._前A(key)
    sleep(50)
    if (MyFuns.getKeyState(key)) {
      this._连发A(key)
    }
  }

  /* 重载宏接口
  */
  _setMacro(){
    super._setMacro()
    this.macroMap["植物左右连打"] := this._植物左右连打.bind(this)
    this.macroMap["植物吞人"] := this._植物吞人.bind(this)
    this.macroMap["下上A连打"] := this._下上A连打.bind(this)
    this.macroMap["前A连打"] := this._前A连打.bind(this)
    this.macroArr := MyFuns.arrCombine(this.macroArr, ["植物左右连打", "植物吞人", "下上A连打", "前A连打"])
  }

}

/* 运行当前脚本
*/ if (A_ScriptName == "战斗回路.2.ahk") {
  face := FaceDetector() ;方向检测对象
  macro := BatcirMacro(face, ["q","f"]) ;宏对象,有界面时第二个参数可以随便写但长度不要小于2
  ;宏方案预设,用于菜单
  preset := Map("默认", ["连发A", "下上A连打", "蓄力A", "下前A", "前A连打", "植物左右连打", "植物吞人"])
  ;新建界面并设定
  ui := CommonUI("战斗回路", macro ,preset)
  ui.setup()
  ui._gameKeyEdit.Text := "q,f"
  ui._hotkeyEdit.Text := "~d,~s,c,e,~g,~r,v"
  ui.readPresetMenu("默认")
}